package com.example.demo.config;

import com.example.demo.Util.MapToObj;
import com.example.demo.Util.PropertiesUtil;
import com.example.demo.dto.SysSetting;

import java.util.Map;
import java.util.Properties;


public class ApiConstant {


    public  static  int size=4;//喵趣每页显示的条数


    /**
     *用户信息保存在Sessioon的标示
     */
    public static final String USER_IDENTIFICATION="USER_IDENTIFICATION";

    //    public  static final  String APIID="wx8dda79ec80a523ba";
//    public  static final  String SECRET="66f62ebcc73772e36b92532d086dce48";
    public  static   String APIID="wx02199ee9800e756f";  //小程序ID
    public  static   String SECRET="70ccb86690a960d71d8c8c76fe043c6a";//小程序 SECRET
    public  static   String GRANTTYPE="authorization_code"; //小程序第三方 获取 openid 方式
    public  static   String WX_OPENIDURL="https://api.weixin.qq.com/sns/jscode2session"; //小程序第三方获取 openid API地址

    public  static   String WX_ACCESS_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token"; //小程序第三方登录API地址
    public  static   String WX_ACCESS_TOKEN_OPTION="client_credential"; //小程序第三方登录方式

    public  static   String WX_QR_CODE_PAGE="pages/index/index";
    public  static   String WX_QR_CODE_URL="https://api.weixin.qq.com/wxa/getwxacodeunlimit";

    public static    String WX_SMS_CODE_KEY="WXSMSCODE";


    public  static   String WX_M_id="1519507101";  //商户号

    public  static   String WX_PAY_NOTICE="https://wxapi.exbike.cn/api/pay/notice"; //通知地址
    public  static   String WX_PAY_KEY="&key=DaHuiHuiBikeSecret12345678912345"; //商户KEY


    public static    Double WX_MAP_RADIO=0.01; //设备列表范围





    public static int getSize() {
        return size;
    }

    public static void setSize(int size) {
        ApiConstant.size = size;
    }


    public static String getUserIdentification() {
        return USER_IDENTIFICATION;
    }

    public static String getAPIID() {
        return APIID;
    }

    public static String getSECRET() {
        return SECRET;
    }

    public static String getGRANTTYPE() {
        return GRANTTYPE;
    }

    public static String getWxOpenidurl() {
        return WX_OPENIDURL;
    }

    public static String getWxAccessTokenUrl() {
        return WX_ACCESS_TOKEN_URL;
    }

    public static String getWxAccessTokenOption() {
        return WX_ACCESS_TOKEN_OPTION;
    }

    public static String getWxQrCodePage() {
        return WX_QR_CODE_PAGE;
    }

    public static String getWxQrCodeUrl() {
        return WX_QR_CODE_URL;
    }

    public static String getWxSmsCodeKey() {
        return WX_SMS_CODE_KEY;
    }



    public static String getWX_M_id() {
        return WX_M_id;
    }

    public static String getWxPayNotice() {
        return WX_PAY_NOTICE;
    }

    public static String getWxPayKey() {
        return WX_PAY_KEY;
    }



    public static void setAPIID(String APIID) {
        ApiConstant.APIID = APIID;
    }

    public static void setSECRET(String SECRET) {
        ApiConstant.SECRET = SECRET;
    }

    public static void setGRANTTYPE(String GRANTTYPE) {
        ApiConstant.GRANTTYPE = GRANTTYPE;
    }

    public static void setWxOpenidurl(String wxOpenidurl) {
        WX_OPENIDURL = wxOpenidurl;
    }

    public static void setWxAccessTokenUrl(String wxAccessTokenUrl) {
        WX_ACCESS_TOKEN_URL = wxAccessTokenUrl;
    }

    public static void setWxAccessTokenOption(String wxAccessTokenOption) {
        WX_ACCESS_TOKEN_OPTION = wxAccessTokenOption;
    }

    public static void setWxQrCodePage(String wxQrCodePage) {
        WX_QR_CODE_PAGE = wxQrCodePage;
    }

    public static void setWxQrCodeUrl(String wxQrCodeUrl) {
        WX_QR_CODE_URL = wxQrCodeUrl;
    }

    public static void setWxSmsCodeKey(String wxSmsCodeKey) {
        WX_SMS_CODE_KEY = wxSmsCodeKey;
    }



    public static void setWX_M_id(String WX_M_id) {
        ApiConstant.WX_M_id = WX_M_id;
    }

    public static void setWxPayNotice(String wxPayNotice) {
        WX_PAY_NOTICE = wxPayNotice;
    }

    public static void setWxPayKey(String wxPayKey) {
        WX_PAY_KEY = wxPayKey;
    }



    public static void setWxMapRadio(Double wxMapRadio) {
        WX_MAP_RADIO = wxMapRadio;
    }



    public static Double getWxMapRadio() {
        return WX_MAP_RADIO;
    }

    public static SysSetting getSysSetting(){
        SysSetting sysSetting=new SysSetting();
        sysSetting.setAPIID(getAPIID());
        sysSetting.setSECRET(getSECRET());

        sysSetting.setWX_M_id(getWX_M_id());
        sysSetting.setWX_MAP_RADIO(getWxMapRadio());
        sysSetting.setWX_PAY_KEY(getWxPayKey());
        sysSetting.setWX_PAY_NOTICE(getWxPayNotice());


        return  sysSetting;
    }

    public static SysSetting setSysSetting(SysSetting sysSetting){

        setAPIID(sysSetting.getAPIID());
        setSECRET(sysSetting.getSECRET());

        setWX_M_id(sysSetting.getWX_M_id());
        setWxMapRadio(sysSetting.getWX_MAP_RADIO());
        setWxPayKey(sysSetting.getWX_PAY_KEY());


        PropertiesUtil p=new PropertiesUtil();
        SysSetting apiConstant= ApiConstant.getSysSetting();
        try {
            p.WriteProperties(MapToObj.objectToMap(apiConstant));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return  sysSetting;
    }


    public static void init(){
        PropertiesUtil p=new PropertiesUtil();
        Properties pps=p.loadConfig();
        Map map=p.getAllProperties(pps);
        System.out.println(map);
        SysSetting sysSetting=(SysSetting) MapToObj.MapToObj(map,SysSetting.class);
        setSysSetting(sysSetting);
    }
}

